package com.campus.admin.controller;




import com.campus.common.core.domain.AjaxResult;
import com.campus.service.StatisticService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@Slf4j
@RequestMapping("/system/admin/statistic")
public class StatisticController {

    @Autowired
    private StatisticService statisticService;

    /**
     * 每日发布帖子数量统计
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/articleNum")
    public AjaxResult articleNumByDay(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime){

        return AjaxResult.success("success", statisticService.getArticleNum(beginTime,endTime));
    }

    /**
     * 返回前5点赞数帖子
     * @return
     */
    @GetMapping("/top")
    public AjaxResult top5(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
                           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime){
        return AjaxResult.success("success",statisticService.top5(beginTime, endTime));
    }

    /**
     * 每日新增用户统计
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/userNum")
    public AjaxResult userNumByDay(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime){

        return AjaxResult.success("success", statisticService.getUserNum(beginTime,endTime));
    }

    /**
     * 统计每个墙分类下的帖子数量
     * @return
     */
    @GetMapping("/artNumByCategory")
    public AjaxResult artNumByCategory(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
                                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime){
        return AjaxResult.success("success", statisticService.getArtNumByCategory(beginTime, endTime));
    }
}
